<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <link rel="stylesheet" type="text/css" href="/static/themes/metro-blue/easyui.css">
    <link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/css/lbd.css">
    <link rel="stylesheet" type="text/css" href="/static/themes/icon.css">
    <script type="text/javascript" src="/static/decimal.min.js"></script>
</head>
<body>
<!--nav-->

<div class="easyui-layout" style="width:100%; height: 100%;">
    <div data-options="region:'north',split:true" style="height:50px;overflow: hidden;">
        <div class="easyui-layout" style="width:100%; height: 100%;  ">
            <div data-options="region:'west'" class="west" style="width:182px">
                <div class="logo" onclick="goHome()"><img src="/static/img/logo.png"></div>
            </div>
            <div data-options="region:'center'" class="usertop">
                <div class="userinfo">
                    <span class="lasttime">上次登录时间：<span class="lastLoginTime"></span></span>
                    <span class="welcome">欢迎您:<span class="realName"></span></span>
                    <span class="userlogout"><a class="logout" href="/login.html">退出</a></span>
                </div>
            </div>
        </div>
    </div>
    <div data-options="region:'west'" class="west" style="width:182px">
        <div id="accordionMenu" class="easyui-accordion" style="width:180px;">

        </div>
    </div>
    <div id="mainPanle" region="center" border="true" border="false">
    </div>
    <div data-options="region:'south',split:true" style="height:20px;text-align: center;background: #f3f3f3">
        2016乐百贷p2p系统
    </div>
</div>
<!-- 窗口组件 -->
<div id="win" class="easyui-window"></div>
</body>

<!--js库-->
<script type="text/javascript" src="/static/jquery.min.js"></script>
<script type="text/javascript" src="/static/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/static/jquery.easyui.fn.default.js"></script>
<script type="text/javascript" src="/static/common.js"></script>
<script type="text/javascript" src="/static/validate.js"></script>
<!--引入CSS-->
<link rel="stylesheet" type="text/css" href="/static/webuploader-0.1.5/webuploader.css">
<!--引入JS-->
<script type="text/javascript" src="/static/webuploader-0.1.5/webuploader.js"></script>
<script>
    //全局错误处理
    $.ajaxSetup({
        error: function (xhr, status, error) {
            switch (xhr.status) {
                case(500):
                    $.messager.alert('错误提示', '服务器系统内部错误,请联系管理员!', 'error');
                    break;
                case(403):
                case(404):
                    $.messager.alert('错误提示', '无权限访问!', 'error');
                    break;
                //未登录
                case(499):
                    window.location = "/login.html";
                    break;
                case(408):
                    $.messager.alert('错误提示', '请求超时!', 'error');
                    break;
                default:
                    $.messager.alert('错误提示', '未知错误!', 'error');
            }
        }
    });
    $.parser.auto = false;
    function goHome() {
        $('#mainPanle').panel('refresh', "/home.html");
        window.location = (window.location + "").split("#")[0];
    }
    function loadMenu() {
        $.get("/menu/loadMenu", function (data) {
            if (data.state == "SUCCESS") {
                var menus = data.data;
                var level1 = [];
                $.each(menus, function (i, v) {
                    var lv = '<div title="' + v.name + '" data-options="iconCls:\'' + v.icon + '\'" style="overflow:auto;">' +
                            '<ul class="childmenu">';
                    var lis = [];
                    $.each(v.children, function (j, c) {
                        var li = '<li index="' + i + '" data-url="' + c.url + '">' +
                                '<a href="#" class="easyui-linkbutton amenu" data-options="iconCls:\'' + c.icon + '\'">' + c.name + '</a>' +
                                ' </li>';
                        lis.push(li)
                    });
                    lv = lv + lis.join("")
                            + '</ul>' +
                            '</div>';
                    level1.push(lv);
                });
                $("#accordionMenu").append(level1.join(""));
                $.parser.parse();
                $.parser.auto = true;
            }
        });
    }

    loadMenu();
    var a = 0;
    var ls = (window.location + "").split("#");
    $.parser.onComplete = function () {
        //移除easyui输入框的style属性
        $(".querybycon input[id^=_easyui_textbox_input]").each(function (i, v) {
            $(v).removeAttr("style");
        })

        if (a > 0) {
            return false;
        }
        a++;
        //如果页面是打开的
        if (ls.length > 1 && ls[1]) {
            var index = $("li[data-url='" + ls[1] + "']").attr("index");
            $('#accordionMenu').accordion('select', parseInt(index));
            $('#mainPanle').panel('refresh', ls[1]);
        } else {
            $('#mainPanle').panel('refresh', "/page/home.html");
        }
        //设置样式
        $(".childmenu li a").on("click", function (event) {
            $(this).addClass("active").parent().siblings().find("a").removeClass("active");
            $(this).parents('div').siblings().find('a').removeClass("active");
            event.preventDefault();
        });
        // 加载菜单
        $(".childmenu li").on("click", function () {
            var url = $(this).attr("data-url");
            $('#mainPanle').panel('refresh', url);
            window.location = ls[0] + "#" + url;
        });


        //加载用户信息
        $.getJSON("/employee/info", function (msg) {
            if (msg.state == "SUCCESS") {
                $.each(msg.data, function (i, v) {
                    $("." + i).html(v);
                })
            } else {
                $.messager.show({
                    title: '操作提示',
                    msg: msg.message,
                    timeout: 2000,
                    showType: 'slide'
                });
            }
        });
    }

    var dic = [];
    $.getJSON("/dictionary/all/keys", {t: Math.random()}, function (data) {
        data = data.data;
        for (var i = 0; i < data.length; i++) {
            var items = [];
            for (var j = 0; j < data[i].items.length; j++) {
                items[data[i].items[j].code] = data[i].items[j].name;
            }
            dic[data[i].code] = items;
        }
        console.log(dic);
    })
</script>
</html>